package MineGod;

import java.util.ArrayList;

public class BlockStoneGenerator extends BlockGenerator {
	public BlockStoneGenerator(){
		super(BlockType.stone);
	}
	
	public Block provideBlock(){
		return new BlockStone();
	}
	
	public ArrayList<int[]> generateVein(Chunk chunk) {
		int i = Chunk.rand.nextInt(chunk.blocks.length);
		int j = Chunk.rand.nextInt(chunk.blocks[i].length);
		
		if (chunk.blocks[i][j].isSolid){
			chunk.blocks[i][j] = provideBlock();
		}
		ArrayList<int[]> offRightOrLeft = new ArrayList<int[]>();
		
		//Now create the vein
		for (int k = 0; k < (Chunk.rand.nextInt(maxVeinLength-minVeinLength+1)+minVeinLength); k++){
			ArrayList<int[]> valid = new ArrayList<int[]>();
			for(int x = -1; x <= 1; x++) {
				for(int y = -1; y <= 1; y++) {
					if(!(x == 0 && y== 0)) {
						int checkX = i + x;
						int checkY = j + y;
						if(!(checkX < 0 || checkX >= chunk.blocks.length || checkY < 0 || checkY >= Chunk.CHUNK_HEIGHT) && !(chunk.blocks[checkX][checkY].type == type)){
							valid.add(new int[] {checkX,checkY});
						}
						else if ((checkX < 0 || checkX >= chunk.blocks.length) && !(checkY < 0 || checkY >= Chunk.CHUNK_HEIGHT)){
							valid.add(new int[] {checkX,checkY});
						}
					}
				}
			}
			
			if (valid.size() == 0){
				break;
			}
			int[] nextLoc = valid.get(Chunk.rand.nextInt(valid.size()));
			
			
			i = nextLoc[0];
			j = nextLoc[1];
			if(!(j < 0 || j >= Chunk.CHUNK_HEIGHT)){
				if(i >= chunk.blocks.length || i < 0) {
					offRightOrLeft.add(new int[] {i,j});
				}
				else{
					if (chunk.blocks[i][j].isSolid){
						chunk.blocks[i][j] = provideBlock();
					}
				}
			}
		}
		return offRightOrLeft;
	}
	
	
}
